﻿// Implements a view that can be masked
define([
    'Wjs/ui/widgets/foundation/Mask'
],
function () {
    'use strict';

    return Wjs.defineOnce({

        type: 'Maskable',

        internal: {

            initialize: function () {
                var me = this;

                me.onRender(function () { // Make sure the position is not static so the absolute positioning of the mask will work
                    var position = me.getStyleProperty('position');

                    if (!position || position == 'static') {

                        me.setStyle({
                            position: 'relative'
                        });
                    }
                });
            }
        },

        showMask: function (item) {

            this.mask = Wjs.new('Mask')
                            .setParent(this);

            item = item || Wjs.new('View').addClass('wjs-mask-loading'); // Add the default loading element if no overriding item was provided

            this.mask.setItem(item);

            this.mask.render().show();
        },

        hideMask: function () {

            this.mask.hide();

            this.mask.destroy();
        }

    });

});